package com.smag.echarts.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smag.common.core.domain.AjaxResult;
import com.smag.echarts.domain.EchartsLineEconomy;
import com.smag.echarts.domain.vo.EchartsLineEconomyVo;
import com.smag.echarts.service.EchartsLineEconomyService;
import com.smag.echarts.mapper.EchartsLineEconomyMapper;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author hzqhzq
 * @description 针对表【echarts_line_economy】的数据库操作Service实现
 * @createDate 2023-04-21 17:19:18
 */
@Service
public class EchartsLineEconomyServiceImpl extends ServiceImpl<EchartsLineEconomyMapper, EchartsLineEconomy>
        implements EchartsLineEconomyService {

    @Override
    public AjaxResult getEconomyList() {
        List<EchartsLineEconomy> list = list();
        List<Integer> year = new ArrayList<>();
        List<BigDecimal> input = new ArrayList<>();
        List<BigDecimal> cost = new ArrayList<>();
        list.forEach(echartsLineEconomy -> {
            year.add(echartsLineEconomy.getYear());
            input.add(echartsLineEconomy.getInput());
            cost.add(echartsLineEconomy.getCost());
        });
        EchartsLineEconomyVo echartsLineEconomyVo = new EchartsLineEconomyVo();
        echartsLineEconomyVo.setYear(year);
        echartsLineEconomyVo.setInput(input);
        echartsLineEconomyVo.setCost(cost);
        return AjaxResult.success(echartsLineEconomyVo);
    }

    @Override
    public List<EchartsLineEconomy> selectEchartsLineEconomyList(EchartsLineEconomy echartsLineEconomy) {
        LambdaQueryWrapper<EchartsLineEconomy> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(ObjectUtils.isNotNull(echartsLineEconomy.getYear()),EchartsLineEconomy::getYear,echartsLineEconomy.getYear());
        queryWrapper.like(ObjectUtils.isNotNull(echartsLineEconomy.getInput()),EchartsLineEconomy::getInput,echartsLineEconomy.getInput());
        queryWrapper.like(ObjectUtils.isNotNull(echartsLineEconomy.getCost()),EchartsLineEconomy::getCost,echartsLineEconomy.getCost());
        return list(queryWrapper);
    }

    @Override
    public AjaxResult selectEchartsLineEconomyById(Long id) {
        return AjaxResult.success(getById(id));
    }

    @Override
    public AjaxResult insertEchartsLineEconomy(EchartsLineEconomy echartsLineEconomy) {
        if (save(echartsLineEconomy)) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @Override
    public AjaxResult updateEchartsLineEconomy(EchartsLineEconomy echartsLineEconomy) {
        if (updateById(echartsLineEconomy)) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @Override
    public AjaxResult deleteEchartsLineEconomyByIds(Long[] ids) {
        if (getBaseMapper().deleteEchartsLineEconomyBatchByIds(ids) > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
}




